/*
 * File Name:               XCoroutineManager.cs
 * 
 * Description:             协程统一处理
 * Author:                  lisiyu <576603306@qq.com>
 * Create Date:             2016/11/29
 */

using System.Collections;
using UnityEngine;

public class XCoroutineManager : SingletonTemplate<XCoroutineManager>
{
    public delegate Coroutine StartCoroutineHandler(IEnumerator routine);
    public delegate void StopCoroutineHandler(Coroutine routine);

    private StartCoroutineHandler mStartCoroutineEvent;
    private StopCoroutineHandler mStopCoroutineEvent;

    public void setHandlers(StartCoroutineHandler startEvent, StopCoroutineHandler stopEvent)
    {
        mStartCoroutineEvent = startEvent;
        mStopCoroutineEvent = stopEvent;
    }

    public Coroutine startCoroutine(IEnumerator routine)
    {
        if (mStartCoroutineEvent == null)
            return null;

        return mStartCoroutineEvent(routine);
    }

    public void stopCoroutine(Coroutine routine)
    {
        if (mStopCoroutineEvent == null)
            return;

        mStopCoroutineEvent(routine);
    }
}
